//AMEBA CSS REMOVE
$('head link[type^="text/css"]:not([href^="http://usercss.ameblo.jp/"])').remove();

//OPEN GRAPH PROTOCOL
$('html').attr('xmlns:fb','http://www.facebook.com/2008/fbml');
$('head').append(
	'<meta property="fb:admins" content="100001593001070" />'+
	'<meta Property="fb:page_id" content="143083302446346" />'+
	'<meta property="og:title" content="'+document.title+'" />'+
	'<meta property="og:type" content="article" />'+
	'<meta property="og:url" content="'+encodeURIComponent(location.protocol+'//'+location.hostname+location.pathname)+'" />'+
	'<meta property="og:image" content="http://dl.dropbox.com/u/33538808/ameba/img/logo_2.png" />'+
	'<meta property="og:site_name" content="デジタリアン 4 ameba" />'+
	'<meta property="fb:app_id" content="119425981488740" />'
);

//AddThis
$(function(){
var entryURL = $('.foot a:contains("記事URL")').attr('href');
var amebloShareContents = '<a href="'+entryURL+'" target="_blank">'+document.title+'</a>';
var amebloShareURL = 'http://blog.ameba.jp/ucs/entry/srventryinsertinput.do?entry_text='+encodeURIComponent(amebloShareContents)+'&editor_flg=1';
var fbLikeButton = '<iframe src="//www.facebook.com/plugins/like.php?href='+entryURL+'&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=119425981488740" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px; margin:2px 2px 0 0; float: left; clear: both;" allowTransparency="true"></iframe>';

addThisBar = 
'<div class="addthis_toolbox addthis_default_style addthis_32x32_style " style="position:absolute;top:0;left:0;height:32px;width:640px;">'+
	'<a class="addthis_button_facebook"></a>'+
	'<a class="addthis_button_twitter"></a>'+
	'<a class="opacity" href="http://stat100.ameba.jp/blog/proxy.html?longurl='+encodeURIComponent(entryURL)+'&type=mixi" target="_blank" rel="nofollow" alt="mixiチェク" title="mixiチェック" style="float:left;display:block;width:32px;height:32px;padding:0 2px;background:url(http://dl.dropbox.com/u/33538808/img/icon/icon_mixi.png) no-repeat 50% 50%;"></a>'+
	'<a class="opacity" href="'+amebloShareURL+'" target="_blank" alt="アメブロで書く" title="アメブロで書く" style="float:left;display:block;width:32px;height:32px;padding:0 2px;background:url(http://dl.dropbox.com/u/33538808/img/icon/icon_ameba.png) no-repeat 50% 50%;"></a>'+
	'<a class="addthis_button_email"></a>'+
	'<a class="opacity" href="http://rssblog.ameba.jp/mattintosh/rss20.xml" target="_blank" alt="RSS" title="RSS" style="float:left;display:block;width:32px;height:32px;padding:0 2px;background:url(http://dl.dropbox.com/u/33538808/img/icon/1321890291_rss.png) no-repeat 50% 50%;"></a>'+
	'<a class="addthis_button_compact"></a>'+
	'<a class="addthis_counter addthis_bubble_style"></a>'+
	'<a class="amebaReaderButton" href="http://blog.ameba.jp/reader.do?bnm=mattintosh" target="_blank">アメーバ読者登録</a>'+
	'<a class="amebaTwitterButton" href="http://twitter.com/mattintosh4" target="_blank">Follow on Twitter</a>'+
	fbLikeButton+
	'<a class="addthis_button_google_plusone"g:plusone:size="medium"style="margin:2px 0 0;"></a>'+
'</div>'+
'<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4ec7c57d428cd34f" />'+
'<script type="text/javascript">'+
'var addthis_config={"data_track_clickback":true};'+
'var addthis_share={templates:{twitter:"RT @mattintosh4 『{{title}}』 {{url}}"}}</script>';
$('.contents').prepend(addThisBar);
});

// GOOGLE PROJECT HOSTING SCRIPT
$.getScript('http://digitalian4.googlecode.com/svn/trunk/ameblo_oldSkin/themeLinkReplacer.js');
$.getScript('http://digitalian4.googlecode.com/svn/trunk/ameblo_oldSkin/addThemeParents.js');
$.getScript('http://digitalian4.googlecode.com/svn/trunk/ameblo_oldSkin/archiveLinkReplacer.js');

// FC2 ACCESS RANKING
// $.getScript('http://9552354.ranking.fc2.com/analyze.js');
$.getScript('http://mattintosh4.googlecode.com/svn/ameblo_mattintosh/analyze.js');

// FOR ALL PAGES START /////////
$(function(){

// サイドバーの広告の高さをリセット
$(window).load(function(){
  $('#attentionBox div.ad_frame div').removeAttr('style')
});

// ARCHIVES SLIDE MENU
  $('#archives li').hide();
  for(var i=2004;i<2014;i++){
    var archivesParentsUnit = '<li id="archives_'+i+'" class="archivesParents" style="cursor:pointer;">Archives '+i+'</li>';
    $('#archives li:contains('+i+')').addClass('archives_'+i);
    $('.archives_'+i).eq(0).before(archivesParentsUnit);
  };
  $('#archives .archivesParents').toggle(function(){
    $(this).nextUntil('[id]').slideDown();
    $(this).toggleClass('archivesParentsOpen');
  },function(){
    $(this).nextUntil('[id]').slideUp();
    $(this).toggleClass('archivesParentsOpen');
  });

	// SPAN FOR MENU TITLE
	$('h4.menu_title').wrapInner('<span>');
	// SIDE TITLE REPLACE
	$('#theme_list h4.menu_title span').html('Blog Themes');
	$('#recent_comment h4.menu_title span').html('Recent Comments');
	$('#archives h4.menu_title span').html('Archives');
	$('#calendar h4.menu_title span').html('Calendar');
	$('#calendar td:empty').css('visibility','hidden');
	$('#calendar td:not(:has(a))').css('opacity','0.5');

	$('#header').prepend('<a href="http://www.ameba.jp/" id="amebaLogin" class="opacity"></a>');
	$('#header').append(
		'<ul id="pageGuide" class="clearfix">'+
		'<li><a href="http://ameblo.jp/mattintosh/" alt="トップページ" title="トップページ">&lt;&lt;</a></li>'+
		'<li><a class="prevP">&lt;</a></li>'+
		'<li><a class="nextP">&gt;</a></li>'+
		'</ul>'
	);
	$('.entry:last').after('<div class="pn"><a class="prevP"></a><a class="nextP"></a></div>');
	$('.prevP').attr('href',$('.previousPage').eq(0).attr('href'));
	$('.prevP').attr('title',$('.previousPage').eq(0).attr('title'));
	$('.nextP').attr('href',$('.nextPage').eq(0).attr('href'));
	$('.nextP').attr('title',$('.nextPage').eq(0).attr('title'));
	$('.pn .prevP').html('<span class="small">[←新しい記事]</span><br>'+$('.previousPage').eq(0).attr('title'));
	$('.pn .nextP').html('<span class="small">[古い記事→]</span><br>'+$('.nextPage').eq(0).attr('title'));
	$('.prevP:not([href]), .nextP:not([href])').css('display','none');

// LIGHTBOX PLUGIN
$('a.lightbox,a[rel="lightbox"]').colorbox();
$('a.youtube').colorbox({iframe:true,width:640,height:480});

// FOR ALL PAGES END ///////////
});



// OTHER PAGES /////////////////
var Index = /^http:\/\/ameblo.jp\/mattintosh\/?$/;
var Location = location.protocol+'//'+location.hostname+location.pathname;
if(Index.test(Location)==false){
// START ///////////////////////
$(function(){
// ENTRY TITLE LINK & THEME MOVING & ENTRY EDITOR LINK
var EntTitle = $('.entry h3.title');
var EntAnch = $('.foot a:contains("記事URL")');
for(var i=0,n=EntAnch.length;i<n;i++){
	EntLink = $(EntAnch).eq(i).attr('href');
	$(EntTitle).eq(i).wrapInner('<a href="'+EntLink+'" title="'+$(EntTitle).eq(i).text()+'">'); // ENTRY TITLE LINK
	$('.theme').eq(i).appendTo('.entry_head').eq(i); // THEME MOVING
	var EntEdit = EntLink.replace(/.+?([0-9]+?)\.html/,'http://blog.ameba.jp/ucs/entry/srventryupdateinput.do?id=$1');
	$('.entry_head').eq(i).prepend('<a href="'+EntEdit+'" alt="記事編集(管理人専用)" title="記事編集(管理人専用)" style="display:inline-block;width:16px;height:16px;background:url(http://dl.dropbox.com/u/33538808/img/icon/32x32%20Mono%20Icons%20-%20Tutorial9/pencilplus16.png) no-repeat 50% 50%;"></a>');
}

// TAGS LINKS
$(function(){
	var tags = $('div.tags');
	for(var i=0,l=tags.length;i<l;i++){
		var hash = tags[i].innerHTML.split(',');
		for(var j=0,jl=hash.length;j<jl;j++){
			hash[j] = hash[j].replace(/^\s?(.+?)$/g,'$1');
			var gcs = 'http://www.google.co.jp/cse?cx=partner-pub-0162616331513802%3A6817031282&ie=UTF-8&q='+hash[j]+'&sa=%E6%A4%9C%E7%B4%A2&siteurl='+encodeURIComponent(location.hostname+location.pathname)+'#gsc.tab=0&gsc.q='+hash[j]+'&gsc.page=1';
			hash[j] = '<li><a href="'+gcs+'" target="_blank">'+hash[j]+'</a></li>';
		}
		hash.unshift('<ul class="clearfix">');
		hash.push('</ul>');
		tags[i].innerHTML = hash.join('');
	}
	$('div.tags').prepend('<h6>この記事に関連付けされているタグ</h6>');
});

var gcsBox = '<form action="http://www.google.co.jp/cse" id="cse-search-box">'+
'<div>'+
'<input type="hidden" name="cx" value="partner-pub-0162616331513802:6817031282" />'+
'<input type="hidden" name="ie" value="UTF-8" />'+
'<input type="text" name="q" size="40" />'+
'<input type="submit" name="sa" value="検索" />'+
'</div>'+
'</form>'+
'<script type="text/javascript" src="http://www.google.co.jp/coop/cse/brand?form=cse-search-box&amp;lang=ja"></script>';
$('div.tags').after(gcsBox);

// COMMENT AUTHOR SELECTOR
ca = $('.comment_author');
for(var i=0,n=ca.length;i<n;i++){
	cal = $(ca).eq(i).children('a');
	ec = $(ca).eq(i).parents('.each_comment');
	if(cal.length == true){
		caURL = $(cal).attr('href');
		o_comment_reg = /^http:\/\/ameblo\.jp\/mattintosh\//;
		f_comment_reg = /^http:\/\/ameblo\.jp\/(etude666|blog-lab|sochan-2010|lovecosmehanako2|heibon125)\//;
		if(o_comment_reg.test(caURL) == true){
			$(ec).addClass('comment_owner');
		}else{
			if(f_comment_reg.test(caURL) == true){
				$(ec).addClass('comment_friend');
			}else{
				$(ec).addClass('comment_amebauser');
			}
		}
	}else{
		$(ec).addClass('comment_guest');
	}
}
// COMMENT AREA TITLE REPLACER
$('#comment_module h3.title').html('Comments');
$('#comment_module p.list').html('<a href="javascript:commentWinOpenB();">何か書く？</a>');
$('#comment_module h3.title').after(
	'<ul style="list-style:none;margin:0 0 2em;padding:0;" class="small">'+
	'<li>※URLには自動的にリンクが付きます。他の閲覧者が開いても問題のないURL以外は書きこまないで下さい。</li>'+
	'<li>※誤って書き込んでしまった場合は管理人までご連絡下さい。</li></ul>'
);
// COMMENT TITLE REPLACER
$('p.label').wrap('<h4>');
$('p.label').each(function(){$(this).html($(this).html().replace(/.+?■(.+?)$/gi,'$1 <span style="font-size:0.75em;">from</span> '));});
$('.comment_author').each(function(){$(this).appendTo($(this).parents('.each_comment').children('h4').children('p.label'));});
// COMMENT BODY URL REPLACER
$('.comment_body').each(function(){
	$(this).html(
		$(this).html().replace(/(\b)?(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)(\b)?/gi,'<a href="$2$3" target="_blank">$2$3</a>')
	);
});
// PRE BOX COMMENT DECORATION
pre_css = $('pre.css');
for(i=0,n=pre_css.length;i<n;i++){
	var str = $(pre_css).eq(i);
	reg_comment  = /(\/\*.+?\*\/)/gi;
	$(str).html($(str).html().replace(reg_comment,'<span style="color:#999;">$1</span>'));
}
// FC2 PAGE RANKING
var fc2PageRanking = $('script[src^="http://9552354.ranking.fc2.com/accessory.js?rtype=page"] + table');
$(fc2PageRanking).attr('class','fc2PageRanking').insertBefore('#themeBox');
$('.fc2PageRanking thead tr:eq(1) td').removeAttr('style');
$('.fc2PageRanking tbody tr td:nth-child(2)').removeAttr('style').css('font-size','10pt');
$('.fc2PageRanking tbody a').removeAttr('target');

// VALURECOMMERCE
$('div.tags').before('<iframe frameborder="0" allowtransparency="true" height="60" width="468" marginheight="0" scrolling="no" src="http://ad.jp.ap.valuecommerce.com/servlet/htmlbanner?sid=2264495&pid=880451114" marginwidth="0" style="margin: 2em auto 0;display:block;"><script language="javascript" src="http://ad.jp.ap.valuecommerce.com/servlet/jsbanner?sid=2264495&pid=880451114"></script><noscript><a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2264495&pid=880451114" target="_blank" ><img src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2264495&pid=880451114" height="60" width="468" border="0"></a></noscript></iframe>');

// VALURECOMMERCE & LINKSHARE
$(function(){
	var str = $('.subContents p:not(:has("img"))');
	for(var i=0,n=str.length;i<n;i++){
		$(str).eq(i).html(
			$(str).eq(i).html()
				.replace(/(w{0,3}\.?(?:value\s?commerce|バリューコマース)(?:[a-z0-9.]+)?)(?!"|.+?"|<\/a)/gi,'<a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2264495&pid=873780506" target="_blank" ><img src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2264495&pid=873780506" height="1" width="1" border="0">$1</a>')
				.replace(/(w{0,3}\.?(link\s?share|リンクシェア)(?:[a-z0-9.]+)?)(?!"|.+?"|<\/a)/gi,'<a href="http://click.linksynergy.com/fs-bin/click?id=iuO9vlOe8Uo&offerid=78559.10000001&type=3&subid=0">$1</a><img border="0" width="1" height="1" src="http://ad.linksynergy.com/fs-bin/show?id=iuO9vlOe8Uo&bids=78559.10000001&type=3&subid=0" />')
				.replace(/(w{0,3}\.?(dropbox|ドロップボックス)(?:[a-z0-9.]+)?)(?!"|.+?"|<\/a)/gi,'<a href="http://db.tt/0ptElmb" target="_blank">$1</a>')
				.replace(/(ヤマダ電機)/gi,'<a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2264495&pid=873914611" target="_blank"><img src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2264495&pid=873914611" height="1" width="1" border="0">$1</a>')
				//.replace(/(正規表現)/gi,'<a href="http://ameblo.jp/mattintosh/themeentrylist-10046396751.html" class="localLink">$1</a>')
		);
	}
	$('.subContents hr:eq(0)').after(
		'<p>'+
		'<a href="http://ck.jp.ap.valuecommerce.com/servlet/referral?sid=2264495&pid=880456068" target="_blank" ><img src="http://ad.jp.ap.valuecommerce.com/servlet/gifbanner?sid=2264495&pid=880456068" height="1" width="1" border="0">ブロードバンド最安料金比較。価格.com限定プランでさらにお得</a>'+
		'</p><p>'+
		'<a href="http://click.linksynergy.com/fs-bin/click?id=iuO9vlOe8Uo&offerid=78559.10000049&type=3&subid=0">リンクシェアなら１円から報酬ゲット</a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=iuO9vlOe8Uo&bids=78559.10000049&type=3&subid=0"></a>'+
		'</p><hr />'
	);
	$('pre br').before('<img src="http://mattintosh4.googlecode.com/svn/ameblo_mattintosh/img/icon_enter.png" style="margin-left:4px;" />');
});

// AMEBA IMAGE REPLACER
$('.detailOn').one('mouseenter',function(){$('div#naviLink').remove();});
jQuery(function($){
	var a = $('.detailOn img[src^="http://stat.ameba.jp/user_images/"]');
	for(var i=0,n=a.length;i<n;i++){
		var img = a[i];
		var src = $(img).attr('src').replace(/^(http:\/\/.+?\/)[a-z0-9]+_(\d+\.(?:jpe?g|png|gif))$/,'$1o$2');
		$(img).parent('.detailOn').attr({href:src,rel:"lightbox"}).colorbox({transition:"fade"});
	}
});


// OTHER PAGES END /////////////
});
}
//THEME & ARCHIVE VIEWS
$(function(){
	if($('#recent_entries_list').length==true){
		$('.page').eq(0).toggle();
	};
});

//var randnum=Math.floor(Math.random()*10);
//var randnumB=randnum+10;

$(function(){
	var ad = '#ameblo .menu_frame,.gadBox,#comment_present,#footer_ad ul,#resPointAreaWrapper,#gadLogo_footer';
	$('#footerArea').prepend('<div id="adc"></div>');
		$(ad).prependTo('#footerArea');
});